<template>
	<view>
	  <text>{{ remainingTime }}</text>
	</view>
</template>
 
<script>
export default {
  data() {
    return {
      timer: null,
      remainingSeconds: 900, // 15分钟倒计时，以秒为单位
    };
  },
  computed: {
    remainingTime() {
      return this.formatTime(this.remainingSeconds);
    },
  },
  methods: {
    formatTime(time) {
      let minutes = Math.floor(time / 60);
      let seconds = time % 60;
      minutes = minutes < 10 ? '0' + minutes : minutes;
      seconds = seconds < 10 ? '0' + seconds : seconds;
      return `${minutes}:${seconds}`;
    },
    startCountdown() {
      if (this.remainingSeconds === 0) return;
      this.timer = setInterval(() => {
        this.remainingSeconds -= 1;
        if (this.remainingSeconds < 0) {
          this.clearCountdown();
        }
      }, 1000);
    },
    clearCountdown() {
      clearInterval(this.timer);
      this.timer = null;
    }
  },
  mounted() {
    this.startCountdown();
  },
  beforeDestroy() {
    this.clearCountdown();
  }
};
</script>
<style scoped>
 .number {
	display: flex;
	align-items: center;
	width: 100%;
	font-size: 16px;
}
</style>
